# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper

  def in_place_select_editor_field(object, method, tag_options = {}, in_place_editor_options = {})  
    tag = ::ActionView::Helpers::InstanceTag.new(object, method, self)
    tag_options = { :tag => "span",:id => "#{object}_#{method}_#{tag.object.id}_in_place_editor",:class => "in_place_editor_field" }.merge!(tag_options)
    in_place_editor_options[:url] = in_place_editor_options[:url] || url_for({ :action => "set_#{object}_#{method}" , :id => tag.object.id })
    tag.to_content_tag(tag_options.delete(:tag), tag_options) + in_place_select_editor(tag_options[:id], in_place_editor_options)
  end

  def in_place_select_editor(field_id, options = {})
    function = "new Ajax.InPlaceSelectEditor("
    function << "'#{field_id}', "
    function << "'#{url_for(options[:url])}'"
    function << (', ' + options_for_javascript(
        {'selectOptionsHTML' => %('#{escape_javascript(options[:select_options].gsub(/\n/, ""))}')}
      )  
    )
    if options[:select_options]
      function << ')'
      javascript_tag(function)
    end
  end

  def get_current_page(controller)
    if params[:controller] == controller
      return "current"
    else
      return nil
    end
  end

  def grey_text(issue, text)
    if issue.state == "resolved" || issue.state == "finished"
      text = "\<span class=\"grey_text\"\>" + text + "\</\span\>"
    else
      text
    end
  end

  def deleted_normal_text(issue, text)
    if issue.state == "resolved"
      text = "\<span class=\"grey_text\"\>" + text + "\</\span\>"
    elsif issue.state == "finished"
      text = "\<span class=\"deleted_text\"\>" + text + "\</\span\>"
    else
      text
    end
  end

  def delete_text(issue)
    if issue.state == "resolved"
      "deeper_grey"
    elsif issue.state == "finished"
      "delete_text"
    elsif issue.state == "assigned"
      "new_issue_text"
    elsif issue.state == "reopen"
      "reopen_issue_text"
    elsif issue.state == "submitted"
      "unassign_issue_text"
    end
  end

end
